package cn.tedu.jdbc;

import org.junit.Test;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/*
Author     :Dsi
Date       : 2021/11/30 19:09
Description: 模拟用户登录
*/
public class Demo01 {
    public static void main(String[] args) throws Exception {
        b();
    }

    private static void b() throws Exception {
        System.out.println("输入学号：");
        String aa = new Scanner(System.in).nextLine();
        System.out.println("输入姓名：");
        String bb = new Scanner(System.in).nextLine();

        Connection connection = JDBUtils.getDriver("jdbc:mysql//localhost:3307/cgb2110_04", "root", "root");
        /*1.SQL的骨架，？表示SQL语句的占位符*/
        String a = "select students.sno,students.sname from students where sno= ? and sname = ?";

        PreparedStatement preparedStatement = connection.prepareStatement(a);
        preparedStatement.setObject(1, aa);
        preparedStatement.setObject(2, bb);

        ResultSet resultSet = preparedStatement.executeQuery();

        if (resultSet.next()) {
            System.out.println("输入正确");
        } else System.out.println("输入错误");
        connection.close();
        preparedStatement.close();
        resultSet.close();
    }
}
